﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;

namespace YJKArch.DimensionModule
{
	public class TargetConnectionDimensionFilter : ISelectionFilter
	{
		public TargetConnectionDimensionFilter(Dimension dimension)
		{
			Line line = dimension.Curve as Line;
			this.direction = line.Direction;
			this.id = dimension.Id;
		}

		public bool AllowElement(Element elem)
		{
			if (elem.Id != this.id && elem is Dimension)
			{
				Dimension dimension = elem as Dimension;
				if (dimension.DimensionShape == null)
				{
					Line line = dimension.Curve as Line;
					if (line != null && (this.direction.IsAlmostEqualTo(line.Direction, 0.0001) || this.direction.IsAlmostEqualTo(-line.Direction, 0.0001)) && dimension.References != null && dimension.References.Size > 0)
					{
						return true;
					}
				}
			}
			return false;
		}

		public bool AllowReference(Reference reference, XYZ position)
		{
			throw new NotImplementedException();
		}

		private XYZ direction;

		private ElementId id;
	}
}
